package com.itheima.service;

import com.itheima.dao.VisitDao;
import com.itheima.domain.Customer;
import com.itheima.domain.User;
import com.itheima.domain.Visit;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Mr.King on 2017/2/26.
 */
@Transactional
public class VisitService {

    private VisitDao dao;
    public void setDao(VisitDao dao) {
        this.dao = dao;
    }

    public List<User> findUser() {
        return dao.findUser();
    }

    public List<Customer> findCustomer() {
        return dao.findCustomer();
    }

    public void saveAdd(Visit visit) {
        dao.saveAdd(visit);
    }

    public List<Visit> list() {
        return dao.list();
    }

    public void delete(Visit visit) {
        dao.delete(visit);
    }

    public List<Visit> findSerch(Visit visit) {
        //先根据条件去查询用户表，返回关联外键
        List<User> users = dao.findUsers(visit);
        StringBuilder uvid = new StringBuilder();
        //拼接条件
        for (User u : users){
            uvid.append(u.getUid()).append(",");
        }
        return dao.likeSerch(uvid.toString().substring(0,uvid.length()-1));
    }

    public Visit findOne(Visit visit) {
        return dao.findOne(visit.getVid());
    }

    public void saveEdit(Visit visit) {
        dao.saveEdit(visit);
    }
}
